package cz.muni.fi.veles.polygon;

import com.google.common.collect.Lists;
import cz.muni.fi.veles.AbstractLocation;
import cz.muni.fi.veles.MapServer;
import cz.muni.fi.veles.MapUtils;
import cz.muni.fi.veles.maps.AbstractMap;
import java.util.List;
import javax.faces.component.UIComponent;
import javax.faces.component.UIComponentBase;
import org.richfaces.cdk.annotations.Attribute;
import org.richfaces.cdk.annotations.JsfComponent;
import org.richfaces.cdk.annotations.JsfRenderer;

/**
 * Abstract polygon component
 * @author Jan Ferko
 */
@JsfComponent(type=AbstractPolygon.COMPONENT_TYPE,
    family=AbstractPolygon.COMPONENT_FAMILY,
    renderer=@JsfRenderer(family=AbstractPolygon.COMPONENT_FAMILY, type="cz.muni.fi.veles.PolygonRenderer")
)
public abstract class AbstractPolygon extends UIComponentBase{
    public static final String COMPONENT_TYPE = "cz.muni.fi.veles.Polygon";
    public static final String COMPONENT_FAMILY = "cz.muni.fi.veles";

    /**
     * Default value: #FF0000
     * @return stroke color in hexadecimal representation
     */
    @Attribute(defaultValue="#FF0000")
    public abstract String getStrokeColor();

    /**
     * Default value: 1.0
     * Possible value from 0 to 1.0
     * @return stroke opacity 
     */
    @Attribute(defaultValue="1.0")
    public abstract Double getStrokeOpacity();

    /**
     * Default value:4
     * @return  stroke width of polygon
     */
    @Attribute(defaultValue="4")
    public abstract Integer getStrokeWidth();

    /**
     * Default value: #FF0000
     * @return fill color in hexadecimal representation
     */
    @Attribute(defaultValue="#FF0000")
    public abstract String getFillColor();

    /**
     * Default value: 0.4
     * Possible value from 0 to 1.0
     * @return fill opacity of polygon
     */
    @Attribute(defaultValue="0.4")
    public abstract Double getFillOpacity();

    /**
     * Path of polygon
     * @return path of polygon as list of {@link AbstractLocation}
     */
    public List<AbstractLocation> getPath(){
        List<AbstractLocation> path = Lists.newArrayList();
        for(UIComponent component: this.getChildren()){
            if(component instanceof AbstractLocation){
                path.add((AbstractLocation) component);
            }
        }
        return path;
    }

    /**
     * Resolves used map server
     * @return used map server
     */
     public MapServer resolveMapServer(){
        return MapUtils.resolveMapServer(this);
    }

}
